package com.hf.lookatme.zpresenter;

import android.content.Context;

import com.baidu.location.LocationClient;
import com.hf.lookatme.utils.MapUtils;
import com.hf.lookatme.zview.interfaces.IView_Fragment_Me;
import com.orhanobut.logger.Logger;

/**
 * Created by JoeShiguang on 2015/5/20.
 */
public class Presenter_Fragment_Me implements MapUtils.OnMapLocationReturnedListener {

  private IView_Fragment_Me iView_fragment_me;

  private LocationClient locationClient;

  private String location;

  public Presenter_Fragment_Me(IView_Fragment_Me view_fragment_me) {

    this.iView_fragment_me = view_fragment_me;
  }

  /**
   * 获取用户当前位置信息
   *
   * @return
   */
  public void getLocationInfo(Context context) {

    try{
      locationClient = new MapUtils(context, this).initLocationClient();
      locationClient.start();
    }catch (Exception ex){
      Logger.e(ex.toString());
    }
  }

  @Override
  public void onLocationReturned(String location) {

    this.location = location;
    iView_fragment_me.setUserLocation(location);
    locationClient.stop();
  }
}
